﻿package  
{
	import com.saint.bitmapDistortion.BitmapDistortionTest2;
	import com.saint.bitmapDistortion.StretchyElasticImage;
	import com.saint.bitmapDistortion.StretchyImage;
	import com.saint.bitmapDistortion.StretchyImageAnimator;
	import com.saint.bitmapDistortion.tests.ImageCropTest;
	import com.saint.elasticity.tests.ElasticityTest;
	import com.saint.utils.Logger;
	import flash.display.MovieClip;
	import flash.display.Sprite;
	import flash.events.MouseEvent;
	import flash.events.TimerEvent;
	import flash.geom.Point;
	import flash.utils.Timer;
	/**
	 * ...
	 * @author kembera
	 */
	public class Main extends Sprite
	{
		private var stretchyImage:StretchyElasticImage
		private var stretchyAnimator:StretchyImageAnimator;
		private var resetButton:MovieClip;
		private var bg:Sprite = new Sprite();
		
		
		public function Main() 
		{
			Logger.setLogLevel(Logger.CRITICAL);
			
			Logger.info("Main.Main");	
				
			//stretcyImageTest()
			
			elasticity();
		}
		

		
		
		
		
		/**
		 *  elasticity test 			
		 */
		private function elasticity():void
		{				
			var holder:Sprite = new Sprite();
			addChild(holder);
			holder.x = 0;
			holder.y = 00;
			var eTest:ElasticityTest = new ElasticityTest(holder);
		}
		
		
		
		
		
		
		
		/**
		 * stretchy image test
		 */
		private function stretcyImageTest():void 
		{				
			
			/* test cropping images 
			var imageCropTest:ImageCropTest = new ImageCropTest();
			addChild(imageCropTest);*/
			
			
			/* stretchy Image 	*/	
			
			stretchyImage = new StretchyElasticImage(new Goat(), 6, 6);
			stretchyImage.x = 100;
			stretchyImage.y = 20;
			addChild(stretchyImage);
			stretchyImage.init();
			
			/*reset button*/
			resetButton = new ResetButton();
			resetButton.x = 0;
			resetButton.y = 450;
			resetButton.alpha = 0.9;
			resetButton.addEventListener(MouseEvent.CLICK, reset);
			resetButton.mouseChildren = false;
			addChild(resetButton)
			
			
			/* stretchy Image animation */
			stretchyAnimator = new StretchyImageAnimator();		
			
			stage.addEventListener(MouseEvent.CLICK, doTest);
			
		}
		
		
		private function reset(e:MouseEvent):void
		{
			Logger.info("Main.reset");		
			stretchyImage.reset();		
		}
		
		
		
		private function doTest(e:MouseEvent):void 
		{
			Logger.info("Main.doTest " + e.target);		
			Logger.info("Main.doTest " + e.target.alpha);		
			
			
			/* hack to srop invisible buttons triggering the animation */
			//if (e.target.alpha == 1)
			//{		
				//var targetPoint:Point = new Point(e.stageX, e.stageY);			
				//stretchyAnimator.animateImage(stretchyImage, StretchyImageAnimator.SUCK_TO_POINT, { point:targetPoint, time:0.5 } );
			//}
			
		}
		
	}

}